setwd("/home1/30/jc227089/SRE_inv/ran_outs")


d<-c()
for (i in 1:100){
	fname<-paste("SRE_inv_race", i, ".RData", sep="")
	load(fname)
	d<-rbind(d, sim.result)
	rm(sim.result)	
}
save(d, file="raceConcat.RData")
setwd("/home1/30/jc227089/SRE_inv/Figures")
close<-subset(d, d[,1]==1)
far<-subset(d, d[,1]==50)


Xbreaks<-seq(min(d[,2]), max(d[,2]), length.out=50)
Ylim<-c(0, 40)
close.c<-hist(close[,2], col="grey30", plot=F, breaks=Xbreaks)
far.c<-hist(far[,2], breaks=Xbreaks, plot=F)
comb.c<-cbind(close.c$counts, far.c$counts)
png("SRE_inv_raceFig.png", width=20, height=12, units="cm", res=300)
par(cex.lab=1.5, mar=c(5,5,2,2))
temp<-barplot(t(comb.c), beside=T, col=c("grey30", "grey80"), space=c(0,0), ylab="Frequency", xlab="Time to reach end of space (generations)")
xticks<-temp[1,seq(1, 49, 6)]
axis(1, at=xticks, labels=floor(Xbreaks[seq(1, 49, 6)]))
legend(xticks[7], 60, bty="n", legend=c("Close", "Far"), title="Gradient position", fill=c("grey30", "grey80"))
dev.off()


